package com.test;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransaction;

import java.io.IOException;
import java.util.List;

/**
 * Created by jl on 2016/5/19.
 * 一级缓存测试&二级缓存测试
 */
public class CacheDemo {
    public static void main(String[] args) throws IOException {
        SqlSessionFactory factory = MybatisUtils.getSessionFactory("conf.xml");
        SqlSession session = factory.openSession();

        String statement = "com.mapper.testMapper.getQusIds";
        long t1 = System.currentTimeMillis();
        List<Integer> qusIds = session.selectList(statement, 1);
        long t2 = System.currentTimeMillis();
        System.out.println(t2 - t1);
        System.out.println(qusIds.size() + "ge");
        session.commit();

        //flush cache
        String flushStatement = "com.mapper.testMapper.flush";
        session.update(flushStatement);

        long t3 = System.currentTimeMillis();
        List<Integer> qusIds2 = session.selectList(statement, 1);
        long t4 = System.currentTimeMillis();
        System.out.println(t4 - t3);
        System.out.println(qusIds2.size() + "ge");

    }
}
